﻿    /********************************************************************************
        Description:
            
            This script desribes how to install extensions into Postgres
            For this script, we will be using "uuid-ossp" as example.
            "uuid-ossp" is a Postgres extensions that provides UUID to Postgres
    ********************************************************************************/

    -- Step 1: Check what extensions are
    SELECT * FROM pg_extension;

    -- Step 2: See what extensions are installed
    SELECT * FROM pg_available_extensions;

    -- Step 3: Activate the extension
    CREATE EXTENSION "uuid-ossp";

    -- Step 4: Check to confirm that extension is activated
    SELECT * FROM pg_extension;

    -- Step 5: (Optional) Remove extension
    -- DROP EXTENSION "uuid-ossp";

    -- Reference:
    -- Installing "uuid-ossp" library in Postgres 9.1. (new Extension feature)
    -- http://www.postgresql.org/message-id/C5EBF511-835E-4F24-A4E4-6CC0119F48E4@me.com

    -- Test
    SELECT uuid_nil();      -- A "nil" UUID constant, which does not occur as a real UUID.
    SELECT uuid_ns_dns();   -- Constant designating the DNS namespace for UUIDs.
    SELECT uuid_ns_url();   -- Constant designating the URL namespace for UUIDs.
    SELECT uuid_ns_oid();   -- Constant designating the ISO object identifier (OID) namespace for UUIDs. (This pertains to ASN.1 OIDs, which are unrelated to the OIDs used in PostgreSQL.)
    SELECT uuid_ns_x500();  -- Constant designating the X.500 distinguished name (DN) namespace for UUIDs.
    
    SELECT uuid_generate_v1();      -- This function generates a version 1 UUID.
    SELECT uuid_generate_v1mc();    -- This function generates a version 1 UUID but uses a random multicast MAC address instead of the real MAC address of the computer.
    SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org/p'); -- This function generates a version 3 UUID in the given namespace using the specified input name. 
    SELECT uuid_generate_v4();      -- This function generates a version 4 UUID, which is derived entirely from random numbers.
    SELECT uuid_generate_v5(uuid_ns_dns(), 'TEST'); -- This function generates a version 5 UUID, which works like a version 3 UUID except that SHA-1 is used as a hashing method. 

        